package com.my.blog.website;

import com.alibaba.druid.pool.DruidDataSource;
import com.my.blog.website.controller.GlobalExceptionHandler;
import lombok.SneakyThrows;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.net.InetAddress;

/**
 * Mapper扫描
 * 开启定时任务
 * 事务
 */
@MapperScan("com.my.blog.website.dao")
@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
public class cnbs implements ApplicationListener<WebServerInitializedEvent> {
    private static final Logger LOGGER = LoggerFactory.getLogger(cnbs.class);

    public static void main(String[] args) {
        SpringApplication.run(cnbs.class, args);
        System.out.println(
                "                                      bbbbbbb\n" +
                        "                                      b:::::b\n" +
                        "                                      b:::::b\n" +
                        "                                      b:::::b\n" +
                        "                                      b:::::b\n" +
                        "    ccccccccccccccccnnnn  nnnnnnnn    b:::::bbbbbbbbb        ssssssssss\n" +
                        "  cc:::::::::::::::cn:::nn::::::::nn  b::::::::::::::bb    ss::::::::::s\n" +
                        " c:::::::::::::::::cn::::::::::::::nn b::::::::::::::::b ss:::::::::::::s\n" +
                        "c:::::::cccccc:::::cnn:::::::::::::::nb:::::bbbbb:::::::bs::::::ssss:::::s\n" +
                        "c::::::c     ccccccc  n:::::nnnn:::::nb:::::b    b::::::b s:::::s  ssssss\n" +
                        "c:::::c               n::::n    n::::nb:::::b     b:::::b   s::::::s\n" +
                        "c:::::c               n::::n    n::::nb:::::b     b:::::b      s::::::s\n" +
                        "c::::::c     ccccccc  n::::n    n::::nb:::::b     b:::::bssssss   s:::::s\n" +
                        "c:::::::cccccc:::::c  n::::n    n::::nb:::::bbbbbb::::::bs:::::ssss::::::s\n" +
                        " c:::::::::::::::::c  n::::n    n::::nb::::::::::::::::b s::::::::::::::s\n" +
                        "  cc:::::::::::::::c  n::::n    n::::nb:::::::::::::::b   s:::::::::::ss");
        System.out.println("(♥◠‿◠)ﾉﾞ  cnbs启动成功   ლ(´ڡ`ლ)ﾞ-------Gyh郭");
    }

    @SneakyThrows
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        WebServer server = event.getWebServer();
        WebServerApplicationContext context = event.getApplicationContext();
        Environment env = context.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        int port = server.getPort();
        String contextPath = env.getProperty("server.servlet.context-path");
        if (contextPath == null) {
            contextPath = "";
        }
        LOGGER.info("\n---------------------------------------------------------\n" +
                "\tApplication is running! Access address:\n" +
                "\tLocal:\t\thttp://localhost:{}" +
                "\n\tExternal:\thttp://{}:{}{}" +
                "\n---------------------------------------------------------\n", port, ip, port, contextPath);
    }
}
